[% setvar title pack/unpack uncontrovercial enhancements %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>pack/unpack uncontrovercial enhancements</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Ilya Zakharevich &lt;<a href='mailto:ilya@math.ohio-state.edu'>ilya@math.ohio-state.edu</a>&gt;
  Date: 16 September 2000
  Mailing List: <a href='mailto:perl6-language-data@perl.org'>perl6-language-data@perl.org</a>
  Number: 246
  Version: 1
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>This RFC proposes simple enhancements to templates of pack/unpack builtins.
These enhancements do not change the spirit of how pack/unpack is used.
The semantic is enhanced as much as possible under this constaint.</p>
<p>Additional changes to pack/unpack are listed in other proposals.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>The following additional constructs are allowed in pack()/unpack() TEMPLATEs:</p>
<ul>
<li><a name=', and ;'></a><code>,</code> and <code>;</code></li>
<p>denotes the same as whitespace.</p>
<li><a name='[4]'></a><code>[4]</code></li>
<p>denotes the same as <code>4</code>, as in <code>'i[4] S[4]'</code>.</p>
<li><a name='[TEMPLATE]'></a><code>[TEMPLATE]</code></li>
<p>denotes the same as <code>[$LEN]</code>; here $LEN is the length taken by the data
described by the template:  <code>$LEN = length pack TEMPLATE, @something</code>
(as far as it does not depend on @something, so <code>A*</code> is prohibited).
This multiplier makes sense for byte-oriented types only.  For example,
the middle part of <code>'C[32] C[L8] C[64]'</code> will extract <i>the substring</i> which
consists of 8 packed longs.  Similarly, <code>'C[32] x[L8] C[64]'</code> will skip
this substring.</p>
<li><a name='x!LEN'></a><code>x!LEN</code></li>
<p>skip to offset divisible by <code>LEN</code>.  For example, <code>'x![L]'</code> will align
to a long-compatible boundary.</p>
<li><a name='W'></a><code>W</code></li>
<p>a BER encoded double.</p>
<li><a name='w!'></a><code>w!</code></li>
<p>a BER encoded &quot;length&quot;, in other words, an integer encoded as BER lengths are.</p>
<li><a name='(TEMPLATE)'></a><code>(TEMPLATE)</code></li>
<p>a group.  May take a repeatition count either as <code>(Ns)33</code> or as <code>N/(Ns)</code>.</p>
<li><a name='TEMPLATE1//TEMLATE2'></a><code>TEMPLATE1//TEMLATE2</code></li>
<p>On unpack(): <code>TEMPLATE1</code> extracts a number.  This number specifies the number
of following bytes which the TEMPLATE2 should be applied to.  (The difference
with <code>TEMPLATE1/(TEMLATE2)</code> is that in the latter case the number extracted
by <code>TEMPLATE1</code> is not the number of bytes, but the repetition count.)
During pack(), makes the opposite operation.</p>
<p>For example,</p>
<pre>  pack 'n//(A[4] C*)', 'a', 9..14</pre>
<p>does the same as</p>
<pre>  pack 'n A[4] C*', 10, 'a', 9..14</pre>
<p>(this is especially useful with the grouping proposals introduced in a
future RFC).</p>
<li><a name='quad-formats'></a>quad-formats</li>
<p>should work on 32-bit architectures too, using doubles instead (with a
possible precision loss).</p>
</ul>
<a name='MIGRATION ISSUES'></a><h1>MIGRATION ISSUES</h1>
<p>None.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Straightforward.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>RFC142: Enhanced Pack/Unpack</p>
</div>
